home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1779 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  6.0 KB

  1. From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  2. Date: Wed, 27 Jul 94 11:02:46 +0200
  3. Message-Id: <9407270902.AA17262@issan.informatik.uni-dortmund.de>
  4. To: mint@atari.archive.umich.edu
  5. Subject: Improved pipefs
  6.  
  7. This patch changes the pipe fs to use the full size of the pipe buffer
  8. instead of one less.  This may not look very much, but why shouldn't
  9. MiNT be as good as Linux? :-)  Anyway, the data copying should be a
  10. bit more efficient now.
  11.  
  12. --- pipefs.c~    Mon Jul 25 21:14:56 1994
  13. +++ pipefs.c    Mon Jul 25 22:00:44 1994
  14. @@ -76,7 +76,7 @@
  15.  struct pipe {
  16.      int    readers;    /* number of readers of this pipe */
  17.      int    writers;    /* number of writers of this pipe */
  18. -    int    head, tail;    /* pipe head, tail (head == tail for empty) */
  19. +    int    start, len;    /* pipe head index, size */
  20.      long    rsel;        /* process that did select() for reads */
  21.      long    wsel;        /* process that did select() for writes */
  22.      char    buf[PIPESIZ];    /* pipe data */
  23. @@ -469,11 +469,11 @@
  24.      } else tty = 0;
  25.  
  26.  /* set up the pipes appropriately */
  27. -    inp->head = inp->tail = 0;
  28. +    inp->start = inp->len = 0;
  29.      inp->readers = selfread ? 1 : VIRGIN_PIPE; inp->writers = 1;
  30.      inp->rsel = inp->wsel = 0;
  31.      if (outp) {
  32. -        outp->head = outp->tail = 0;
  33. +        outp->start = outp->len = 0;
  34.          outp->readers = 1; outp->writers = selfread ? 1 : VIRGIN_PIPE;
  35.          outp->wsel = outp->rsel = 0;
  36.      }
  37. @@ -591,7 +591,7 @@
  38.  pipe_write(f, buf, nbytes)
  39.      FILEPTR *f; const char *buf; long nbytes;
  40.  {
  41. -    int ptail, phead, j;
  42. +    int plen, j;
  43.      char *pbuf;
  44.      struct pipe *p;
  45.      struct fifo *this;
  46. @@ -607,9 +607,7 @@
  47.  
  48.      if (nbytes > 0 && nbytes <= PIPE_BUF) {
  49.  check_atomicity:
  50. -        r = p->tail - p->head;
  51. -        if (r < 0) r += PIPESIZ;
  52. -        r = (PIPESIZ-1) - r; /* r is the number of bytes we can write */
  53. +        r = PIPESIZ - p->len; /* r is the number of bytes we can write */
  54.          if (r < nbytes) {
  55.      /* check for broken pipes */
  56.              if (p->readers == 0 || p->readers == VIRGIN_PIPE) {
  57. @@ -629,20 +627,27 @@
  58.      }
  59.  
  60.      while (nbytes > 0) {
  61. -        ptail = p->tail; phead = p->head;
  62. -        j = ptail+1;
  63. -        if (j >= PIPESIZ) j = 0;
  64. -        if (j != phead) {
  65. -            pbuf = &p->buf[ptail];
  66. -            do {
  67. -                *pbuf++ = *buf++;
  68. -                nbytes--; bytes_written++;
  69. -                if ( (ptail = j) == 0 )
  70. -                    pbuf = &p->buf[0];
  71. -                j++;
  72. -                if (j >= PIPESIZ) j = 0;
  73. -            } while ( (nbytes > 0) && (j != phead) );
  74. -            p->tail = ptail;
  75. +        plen = p->len;
  76. +        if (plen < PIPESIZ) {
  77. +            pbuf = &p->buf[(p->start + plen) & (PIPESIZ - 1)];
  78. +            /* j is the amount that can be written continuously */
  79. +            j = PIPESIZ - plen;
  80. +            if (j > nbytes) j = nbytes;
  81. +            nbytes -= j; plen += j;
  82. +            bytes_written += j;
  83. +            while (j--)
  84. +              *pbuf++ = *buf++;
  85. +            if (nbytes > 0 && plen < PIPESIZ)
  86. +              {
  87. +                pbuf = p->buf;
  88. +                j = PIPESIZ - plen;
  89. +                if (j > nbytes) j = nbytes;
  90. +                nbytes -= j; plen += j;
  91. +                bytes_written += j;
  92. +                while (j--)
  93. +                  *pbuf++ = *buf++;
  94. +              }
  95. +            p->len = plen;
  96.          } else {        /* pipe full */
  97.              if (p->readers == 0 || p->readers == VIRGIN_PIPE) {
  98.              /* maybe some other signal is waiting for us? */
  99. @@ -679,7 +684,7 @@
  100.  pipe_read(f, buf, nbytes)
  101.      FILEPTR *f; char *buf; long nbytes;
  102.  {
  103. -    int phead, ptail;
  104. +    int plen, j;
  105.      struct fifo *this;
  106.      struct pipe *p;
  107.      long bytes_read = 0;
  108. @@ -693,19 +698,26 @@
  109.      }
  110.  
  111.      while (nbytes > 0) {
  112. -        phead = p->head; ptail = p->tail;
  113. -        if (ptail != phead) {
  114. -            pbuf = &p->buf[phead];
  115. -            do {
  116. -                *buf++ = *pbuf++;
  117. -                nbytes--; bytes_read++;
  118. -                phead++;
  119. -                if (phead >= PIPESIZ) {
  120. -                    phead = 0;
  121. -                    pbuf = &p->buf[phead];
  122. -                }
  123. -            } while ( (nbytes > 0) && (phead != ptail) );
  124. -            p->head = phead;
  125. +        plen = p->len;
  126. +        if (plen > 0) {
  127. +            pbuf = &p->buf[p->start];
  128. +            /* j is the amount that can be read continuously */
  129. +            j = plen < nbytes ? plen : nbytes;
  130. +            nbytes -= j; plen -= j;
  131. +            bytes_read += j;
  132. +            while (j--)
  133. +              *buf++ = *pbuf++;
  134. +            if (nbytes > 0 && plen > 0)
  135. +              {
  136. +                pbuf = p->buf;
  137. +                j = plen < nbytes ? plen : nbytes;
  138. +                nbytes -= j; plen -= j;
  139. +                bytes_read += j;
  140. +                while (j--)
  141. +                  *buf++ = *pbuf++;
  142. +              }
  143. +            p->len = plen;
  144. +            p->start = pbuf - p->buf;
  145.          }
  146.          else if (p->writers <= 0 || p->writers == VIRGIN_PIPE) {
  147.              TRACE(("pipe_read: no more writers"));
  148. @@ -754,8 +766,7 @@
  149.                  DEBUG(("pipe FIONREAD: no writers"));
  150.                  r = -1;
  151.              } else {
  152. -                r = p->tail - p->head;
  153. -                if (r < 0) r += PIPESIZ;
  154. +                r = p->len;
  155.                  if (is_terminal(f))
  156.                      r = r >> 2;    /* r /= 4 */
  157.              }
  158. @@ -767,9 +778,7 @@
  159.              if (p->readers <= 0) {
  160.                  r = -1;
  161.              } else {
  162. -                r = p->tail - p->head;
  163. -                if (r < 0) r += PIPESIZ;
  164. -                r = (PIPESIZ-1) - r;
  165. +                r = PIPESIZ - p->len;
  166.                  if (is_terminal(f))
  167.                      r = r >> 2;    /* r /= 4 */
  168.              }
  169. @@ -827,11 +836,11 @@
  170.              flushtype = *which;
  171.  
  172.          if ((flushtype & 1) && this->inp) {
  173. -            this->inp->head = this->inp->tail;
  174. +            this->inp->start = this->inp->len = 0;
  175.              wake(IO_Q, (long)this->inp);
  176.          }
  177.          if ((flushtype & 2) && this->outp) {
  178. -            this->outp->head = this->outp->tail;
  179. +            this->outp->start = this->outp->len = 0;
  180.              wake(IO_Q, (long)this->outp);
  181.          }
  182.          break;
  183. @@ -842,8 +851,7 @@
  184.              if (p->readers <= 0) {
  185.                  r = -1;
  186.              } else {
  187. -                r = p->tail - p->head;
  188. -                if (r < 0) r += PIPESIZ;
  189. +                r = p->len;
  190.                  if (is_terminal(f))
  191.                      r = r >> 2;    /* r /= 4 */
  192.              }
  193. @@ -1031,7 +1039,6 @@
  194.  {
  195.      struct fifo *this;
  196.      struct pipe *p;
  197. -    int j;
  198.  
  199.      this = (struct fifo *)f->fc.index;
  200.  
  201. @@ -1043,7 +1050,7 @@
  202.          }
  203.  
  204.  /* NOTE: if p->writers <= 0 then reads won't block (they'll fail) */
  205. -        if (p->tail != p->head || p->writers <= 0) {
  206. +        if (p->len > 0 || p->writers <= 0) {
  207.              return 1;
  208.          }
  209.  
  210. @@ -1057,9 +1064,7 @@
  211.              DEBUG(("write select on wrong end of pipe"));
  212.              return 0;
  213.          }
  214. -        j = p->tail+1;
  215. -        if (j >= PIPESIZ) j = 0;
  216. -        if (j != p->head || p->readers <= 0)
  217. +        if (p->len < PIPESIZ || p->readers <= 0)
  218.              return 1;    /* data may be written */
  219.          if (p->wsel)
  220.              return 2;    /* collision */
  221.  
  222. Diff exited abnormally with code 1 at Mon Jul 25 22:04:20
  223.  
  224. -- 
  225. +------------------------------------------------------------------------+
  226. Andreas Schwab                                      "And now for something
  227. schwab@ls5.informatik.uni-dortmund.de                completely different"
  228.